﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WorkTool
{
	public partial class FileSearcher : UserControl
	{
		public FileSearcher()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			txtResults.Text = "";
			try
			{
				string[] StrResults = System.IO.Directory.GetFiles(txtPath.Text, txtMask.Text, System.IO.SearchOption.AllDirectories);
				List<string>
					results = new List<string>(),
					results2 = new List<string>();
				foreach (string result in StrResults)
					results.Add(result);

				txtContaining.Text = txtContaining.Text.Trim();
				if (!string.IsNullOrEmpty(txtContaining.Text))
					foreach (string result in results)
					{
						string contents = System.IO.File.ReadAllText(result);
						if (cbCaseSensitive.Checked && contents.Contains(txtContaining.Text)) results2.Add(result);
						else if (!cbCaseSensitive.Checked && contents.ToLower().Contains(txtContaining.Text.ToLower())) results2.Add(result);
					}
				else results2 = results;

				foreach (string result in results2)
					txtResults.Text += result + "\r\n";

			}
			catch { }
		}
	
	}
}
